﻿Public Class XLThanNhan
    Private kn As New KNThanNhan
    Public Function BUS_LayDSTN() As DataTable
        Return kn.DSTN
    End Function
    Public Function BUS_SaveTN(ByVal data As DataTable) As Boolean
        Return kn.SaveTN(data)
    End Function
    Public Function BUS_KTra(ByVal tn As DTO_ThanNhan.ThanNhan) As Boolean
        Dim kq As Boolean = False
        If tn.HoTen = "" Then kq = True
        If tn.NamSinh = "" Then kq = True
        If tn.NgheNghiep = "" Then kq = True
        If tn.NguyenQuan = "" Then kq = True
        If tn.NoiLam = "" Then kq = True
        If tn.NoiO = "" Then kq = True
        If tn.QuanHe = "" Then kq = True
        Return kq
    End Function
    Public Function BUS_AddTreePB(ByVal str As String, ByVal mapb As String, ByVal data As DataTable, ByVal dataTN As DataTable) As TreeNode
        Dim tr As New TreeNode(str)
        For Each dr As DataRow In data.Rows
            If dr("MaPhong") = mapb Then
                Dim tr1 As New TreeNode(dr("HoTen"))
                For Each dr2 As DataRow In dataTN.Rows
                    If dr("MaNV") = dr2("MaNV") Then
                        Dim tn As DTO_ThanNhan.ThanNhan
                        tn.MaNV = dr2("MaNV")
                        tn.HoTen = dr2("HoTen")
                        tn.NamSinh = dr2("NamSinh")
                        tn.GioiTinh = dr2("GioiTinh")
                        tn.NguyenQuan = dr2("NQuan")
                        tn.QuanHe = dr2("QuanHe")
                        tn.NgheNghiep = dr2("NgheNghiep")
                        tn.NoiLam = dr2("NoiLam")
                        tn.NoiO = dr2("NoiO")
                        tr1.Nodes.Add(BUS_AddTreeTN(tn))
                        Exit For
                    End If
                Next
                tr.Nodes.Add(tr1)
            End If
        Next
        tr.Tag = str
        Return tr
    End Function
    Public Function BUS_AddTreeTN(ByVal tn As DTO_ThanNhan.ThanNhan) As TreeNode
        Dim tr As New TreeNode(tn.HoTen)
        tr.Nodes.Add(tn.MaNV)
        tr.Nodes.Add(tn.NamSinh)
        tr.Nodes.Add(tn.GioiTinh)
        tr.Nodes.Add(tn.NguyenQuan)
        tr.Nodes.Add(tn.QuanHe)
        tr.Nodes.Add(tn.NgheNghiep)
        tr.Nodes.Add(tn.NoiLam)
        tr.Nodes.Add(tn.NoiO)
        tr.Tag = tn
        Return tr
    End Function
    Public Function BUS_TimThanNhan(ByVal str As String, ByVal data As DataTable, ByVal datatn As DataTable) As List(Of DTO_ThanNhan.ThanNhan)
        Dim ds As New List(Of DTO_ThanNhan.ThanNhan)
        Dim manv As String = BUS_TimMaNV(str, data)
        If manv <> "" Then
            For Each dr As DataRow In datatn.Rows
                If dr("MaNV") = manv Then
                    Dim nv As New DTO_ThanNhan.ThanNhan
                    nv.MaNV = dr("MaNV")
                    nv.HoTen = dr("HoTen")
                    nv.NamSinh = dr("NamSinh")
                    nv.GioiTinh = dr("GioiTinh")
                    nv.NguyenQuan = dr("NQuan")
                    nv.QuanHe = dr("QuanHe")
                    nv.NgheNghiep = dr("NgheNghiep")
                    nv.NoiLam = dr("NoiLam")
                    nv.NoiO = dr("NoiO")
                    ds.Add(nv)
                End If
            Next
        End If
        Return ds
    End Function
    Public Function BUS_TimMaNV(ByVal str As String, ByVal data As DataTable) As String
        Dim kq As String = ""
        For Each dr As DataRow In data.Rows
            If dr("HoTen") = str Then
                kq = dr("MaNV")
                Exit For
            End If
        Next
        Return kq
    End Function
    Public Sub BUS_ThemTN(ByRef dr As DataRow, ByVal tn As DTO_ThanNhan.ThanNhan)
        dr("MaNV") = tn.MaNV
        dr("HoTen") = tn.HoTen
        dr("NamSinh") = tn.NamSinh
        dr("GioiTinh") = tn.GioiTinh
        dr("NQuan") = tn.NguyenQuan
        dr("QuanHe") = tn.QuanHe
        dr("NgheNghiep") = tn.NgheNghiep
        dr("NoiLam") = tn.NoiLam
        dr("NoiO") = tn.NoiO
    End Sub
End Class
